package edu.tongji.engine.plugin.mail;

import edu.tongji.engine.common.Log;
import edu.tongji.engine.common.PropertyUtil;

public class MailNotify {

	PropertyUtil props = new PropertyUtil("resource\\workflow.props");
	MailService mail = new MailService();

	public boolean sendNotifyMail(String subject, String context, String[] to){
		try{
		String host = props.getValue("MAIL_HOST");
		String from = props.getValue("MAIL_FROM");
		String pwd = props.getValue("MAIL_PWD");
		mail.sendMail(host, from, pwd, to, subject, context);
		return true;
		}
		catch(Exception e){
			System.out.println(e.toString());
			Log.getLoger().loger.error("Send Email Fail! ", e);
			return false;
		}
	}
	
	public boolean sendCreateTaskMail(String[] to, Long id){
		String subject = props.getValue("MAIL_CREATE_SUBJECT");
		StringBuilder context = new StringBuilder( props.getValue("MAIL_CREATE_TASK"));
		context.append(" ");
		context.append(id);
		boolean flag = this.sendNotifyMail(subject, context.toString(), to);
		if (flag){
			return true;
		}else{
			Log.getLoger().loger.error("Send create task Email Fail! ");
			return false;
		}
	}

}
